<!DOCTYPE html>
<html  xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8"/>
    <meta name="renderer" content="webkit"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
    <link rel="stylesheet" href="/adminlte/layui/css/layui.css" media="all"/>
    <style>
        .layui-form-label{
            width: 93px;
            font-family: 宋体;
        }

    </style>
</head>

<body >

<form class="layui-form" action="" style="background-color:  #FFFFFF;height:450px">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
        <legend style="color: #0d6aad;font-family: 黑体">订单信息</legend>
    </fieldset>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">客户名称</label>
            <div class="layui-input-inline">
              <!--  <input type="text" name="customerName" lay-verify="required" placeholder="请输入客户名称" autocomplete="off" class="layui-input">-->
                <select   name="customerName" lay-verify="required" lay-search="" lay-filter="customerNameInfo">
                    <option value="">请选择客户名称</option>
                    <option th:each="purchaserName:${purchaserNameList}" th:value="${purchaserName}" th:text="${purchaserName}"></option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">订单日期</label>
            <div class="layui-input-inline">
                <input type="text" name="date" id="date" lay-verify="required" placeholder="请选择订单日期" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">工程名称</label>
            <div class="layui-input-inline">
                <input type="text" name="projectName"   placeholder="请输入工程名称" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">需求日期</label>
            <div class="layui-input-inline">
                <input type="text" name="endDate" id="endDate" lay-verify="required" placeholder="请选择需求日期" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">产品名称</label>
            <div class="layui-input-inline">
                <select name="productNameOrder" lay-verify="required" lay-search="">
                    <option value="">请选择产品名称</option>
                    <option th:each="goodName1:${goodName}" th:value="${goodName1.dataname}" th:text="${goodName1.dataname}"></option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">产品规格</label>
            <div class="layui-input-inline">
                <select name="productSpecificationsOrder"  lay-search="">
                    <option value="">请选择产品规格</option>
                    <option th:each="sysdata1:${sysdata}" th:value="${sysdata1.dataname}" th:text="${sysdata1.dataname}"></option>
                </select>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">使用压力</label>
            <div class="layui-input-inline">
               <!-- <input type="text" name="customerPressure"  lay-verify="required" placeholder="" autocomplete="off" class="layui-input">-->
                <select name="customerPressure" lay-verify="required" lay-search="">
                    <option value="">请选择使用压力 </option>
                    <option th:each="pressure1:${pressure}" th:value="${pressure1.dataname}" th:text="${pressure1.dataname}"></option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">数量</label>
            <div class="layui-input-inline">
                <input type="text" name="customerNums"  lay-verify="required|number" placeholder="请输入数量" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">收货地址</label>
            <div class="layui-input-inline">
                <input type="text" name="address"  lay-verify="required" placeholder="请输入收货地址" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">收货人</label>
            <div class="layui-input-inline">
                <input type="text" name="receiver"  lay-verify="required" placeholder="请输入收货人" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">联系电话</label>
            <div class="layui-input-inline">
                <input type="text" name="telPhone"  lay-verify="phone" placeholder="请输入联系电话" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">开票日期</label>
            <div class="layui-input-inline">
                <input type="text" name="kaiPiaoDate"  id="kaiPiaoDate" placeholder="请选择开票日期" autocomplete="off" class="layui-input">
            </div>
        </div>
     <!--   <div class="layui-inline">
            <label class="layui-form-label">物流信息</label>
            <div class="layui-input-inline">
                <input type="text" name="logisticsInformation"  lay-verify="" placeholder="请输入物流信息" autocomplete="off" class="layui-input">
            </div>
        </div>-->
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">收款日期</label>
            <div class="layui-input-inline">
                <input type="text" name="shouKuanDate"  id="shouKuanDate" placeholder="请选择收款日期" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-inline">
            <input style="width:525px;" type="text" name="remarks" lay-verify="title" autocomplete="off" placeholder="请输入备注" class="layui-input">
        </div>
        </div>
    </div>
    <div class="layui-form-item" style="margin-top: 30px">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="demo" style="margin-left: 300px">立即提交</button>
    <!--        <button type="reset" class="layui-btn layui-btn-primary">重置</button>-->
        </div>
    </div>
</form>
<script src="/adminlte/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="/adminlte/layui/jquery-3.2.1.min.js"></script>
<script>
    layui.use('form', function() {
        var form = layui.form;
        form.on('select(customerNameInfo)', function(data){
            /*console.log(data);*/
            var customerName = $("[name='customerName']").val();
            console.log(customerName+"*****");
            if (customerName!="") {
                $.ajax({
                    //几个参数需要注意一下
                    type: "POST",//方法类型
                    dataType: "json",//预期服务器返回的数据类型
                    url: "/order/userInfott" ,//url
                    data:{customerName:customerName},
                    success: function (result) {
                        console.log(result.success+"------"+result.sysPurchaser)
                        if (result.success>0) {
                            $("[name='address']").val(result.sysPurchaser.localMore);
                            $("[name='receiver']").val(result.sysPurchaser.contacts);
                            $("[name='telPhone']").val(result.sysPurchaser.tel);
                        }else{
                            layer.msg('暂无该公司信息',{
                                btnAlign: 'c',
                                time: 3000, //20s后自动关闭
                                btn: ['确定']
                            });
                        }
                    }
                });
            }else{

            }

        });
        form.on('submit(demo)', function(data){
            /* console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
             console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
             console.log(data.field) *///当前容器的全部表单字段，名值对形式：{name: value}
            /* console.log(JSON.stringify(data.field));*/
            $.ajax({
                url: "/order/addSaleOrder",
                async: true,
                type: "post",
                data: JSON.stringify(data.field),
                dataType: "json",
                contentType: 'application/json; charset=UTF-8',
                success: function(result) {
                    if(result.success >0) {
                        alert("操作成功");
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    } else {
                        console.log(result.date);

                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    }
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    });
    layui.use('laydate',function(){
        var laydate = layui.laydate;
        laydate.render({
            elem: '#date' //指定元素

        });
        laydate.render({
            elem: '#endDate' //指定元素

        });
        laydate.render({
            elem: '#shouKuanDate' //指定元素

        });
        laydate.render({
            elem: '#kaiPiaoDate' //指定元素

        });
    });

</script>
</body>

</html>